/*
 * $Id$
 *
 * Copyright (C) Paris8-IUT de Montreuil, 2012-2013
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */
package fr.paris8.iut.info.iddl.conf;

import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Set;
import java.util.HashSet;
import java.util.Vector;
import java.util.List;

import org.semanticweb.owlapi.model.OWLObject;

public class LocalEntityMap {
	//"key" of maps are Local Ontology Uris,  value sets contain URIs of local concepts and their description  
	private HashMap<String, Set<String>>   concepts = null;
	private HashMap<String, Set<String>>   roles = null;
	private HashMap<String, Set<String>>   dataRoles = null;
	private HashMap<String, Set<String>>   objectRoles = null;
	private HashMap<String, Set<String>>   inds = null;
	
	public LocalEntityMap( ) {
		
		concepts 	= new HashMap(0);
		roles    	= new HashMap(0);
		dataRoles   = new HashMap(0);
		objectRoles = new HashMap(0);
		inds     	= new HashMap(0);
	}
	
	//"ontoUri" : URI of local ontology in which the concept occurs, 
	//"conceptUri" : URI of the concept,
	//"description" would be put here as a third parameter for complex concepts 
	public void addConcept(String ontoUri, String conceptUri) {
		Set<String> cs = concepts.get(ontoUri);
		if(cs==null) {
			Set<String> ss = new HashSet();
			ss.add( conceptUri );
			concepts.put(ontoUri, ss);
		} else cs.add( conceptUri );
	}
	
	public void addRole(String ontoUri, String roleUri) {
		Set<String> rs = roles.get(ontoUri);
		
		if(rs==null) {
			Set<String> ss = new HashSet();
			ss.add( roleUri );
			roles.put(ontoUri, ss);
		} else rs.add( roleUri );
		
	}
	
	public void addObjectRole(String ontoUri, String roleUri) {
		Set<String> rs = objectRoles.get(ontoUri);
		
		if(rs==null) {
			Set<String> ss = new HashSet();
			ss.add( roleUri );
			objectRoles.put(ontoUri, ss);
		} else rs.add( roleUri );
		
	}
	
	public void addDataRole(String ontoUri, String roleUri) {
		Set<String> rs = dataRoles.get(ontoUri);
		
		if(rs==null) {
			Set<String> ss = new HashSet();
			ss.add( roleUri );
			dataRoles.put(ontoUri, ss);
		} else rs.add( roleUri );
		
	}
	
	public void addInd(String ontoUri, String indUri) {
		Set<String> is = inds.get(ontoUri);
		
		if(is==null) {
			Set<String> ss = new HashSet();
			ss.add( indUri );
			inds.put(ontoUri, ss);
		} else is.add( indUri );
	}
	
	public Set<String> getLocalUris() {
		return concepts.keySet();
	}
	
	public Set<String> getConceptsByUri(String uri) {
		return concepts.get(uri);
	}
	
	public Set<String> getRolesByUri(String uri) {
		return roles.get(uri);
	}
	
	public Set<String> getObjectRolesByUri(String uri) {
		return objectRoles.get(uri);
	}
	
	public Set<String> getDataRolesByUri(String uri) {
		return dataRoles.get(uri);
	}
	
	public boolean isObjectRole(String uri, String r) {
		
		Set<String> ors = objectRoles.get(uri);
		if (ors==null) return false;
		if(ors.contains(r)) return true;
		else return false;
		
	}
}
